﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using YAPL.Language.Core.Types;
using Ast = YAPL.Language.Ast;

namespace YAPL.Language.Compiler.CodeGen.ReflectionEmitGenerator.AstGen {
	public class ReReturnGenerator : ReExpressionGenerator {
		public ReReturnGenerator(ReCodeGenerator codeGenerator) : base(codeGenerator) { }
		public override void Generate(Ast.Expression expr) {
			var returnExpression = (Ast.ReturnExpression)expr;

			var gen = Generator.Get<ILGenerator>(ReCodeGenerator.IL_GENERATOR_KEY);
			//Emit return value and store it on top of the stack
			Generator.EmitExpression(returnExpression.Statement);
			//emit return statement
			gen.Emit(OpCodes.Ret);

		}
	}
}
